<!--
 * @Author: Betty
 * @Date: 2021-01-28 23:12:51
 * @LastEditors: Betty
 * @LastEditTime: 2021-02-01 00:02:20
 * @Description: 用户信息组件
-->
<template>
  <!-- 在这里展示用户信息 -->
  <div class="user-container d-flex my-3 align-items-center">
    <img :src="fitUrl" alt="" class="avatar">
    <div class="mx-3 flex-grow-1">
       <p class="nickname">{{userInfo.nickName}}</p>
       <p class="description">{{userInfo.discription || '该用户还没有填写简介'}}</p>
    </div>
  </div>
</template>

<script lang='ts'>
import { computed, defineComponent, PropType } from 'vue'
import { UserProps } from '../store'
import { addColumnAvatar } from '../helper'
export default defineComponent({
  name: '',
  props: {
    // 要传入用户信息
    userInfo: {
        type: Object as PropType<UserProps>,
        required: true
    }
  },
  setup (props) {
    //在这里对头像进行处理，返回处理后的头像
    const fitUrl = computed(() => {
      addColumnAvatar(props.userInfo, 50, 50)
      const { avatar } = props.userInfo
      return avatar && avatar.fitUrl
    })
    return {
      fitUrl
    }
  }
})
</script>

<style>
  img.avatar {
    width: 50px;
    height: 50px;
    padding: 5px;
    border: 1px solid #999;
    border-radius: 50%;
    background-color: #fff;
  }

  p {
    margin: 0;
  }

  .nickname {
    font-size: 16px;
    line-height: 1.5;
    color: #333;
  }

  .description {
    font-size: 14px;
    line-height: 1.5;
    color: #666;
  }
</style>
